package it.poste.il.compensatore.entities;

import java.sql.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="sdprequests")
public class SDPRequest extends BaseEntity {

	private static final long serialVersionUID = -2889083723960626143L;
	
	private String accountingDate;
	private String branch;
	private int workingStationId;
	private int counter;
	private Date timestamp;
	private int numberOperationPdl;
	
	//message id
	@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="sdpRequestId", targetEntity=Message.class)
	private List<Message> message;
	
	public String getAccountingDate() {
		return accountingDate;
	}
	
	public void setAccountingDate(String accountingDate) {
		this.accountingDate = accountingDate;
	}
	
	public String getBranch() {
		return branch;
	}

	public void setBranch(String branch) {
		this.branch = branch;
	}

	public int getWorkingStationId() {
		return workingStationId;
	}
	
	public void setWorkingStationId(int workingStationId) {
		this.workingStationId = workingStationId;
	}
	
	public int getCounter() {
		return counter;
	}
	
	public void setCounter(int counter) {
		this.counter = counter;
	}
	
	public Date getTimestamp() {
		return timestamp;
	}
	
	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}
	
	public int getNumberOperationPdl() {
		return numberOperationPdl;
	}
	
	public void setNumberOperationPdl(int numberOperationPdl) {
		this.numberOperationPdl = numberOperationPdl;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((accountingDate == null) ? 0 : accountingDate.hashCode());
		result = prime * result + ((branch == null) ? 0 : branch.hashCode());
		result = prime * result + counter;
		result = prime * result + ((message == null) ? 0 : message.hashCode());
		result = prime * result + numberOperationPdl;
		result = prime * result
				+ ((timestamp == null) ? 0 : timestamp.hashCode());
		result = prime * result + workingStationId;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SDPRequest other = (SDPRequest) obj;
		if (accountingDate == null) {
			if (other.accountingDate != null)
				return false;
		} else if (!accountingDate.equals(other.accountingDate))
			return false;
		if (branch == null) {
			if (other.branch != null)
				return false;
		} else if (!branch.equals(other.branch))
			return false;
		if (counter != other.counter)
			return false;
		if (message == null) {
			if (other.message != null)
				return false;
		} else if (!message.equals(other.message))
			return false;
		if (numberOperationPdl != other.numberOperationPdl)
			return false;
		if (workingStationId != other.workingStationId)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.getClass().getName() + "[requestId=" + getId() + ", accountingDate="
				+ accountingDate + ", workingStationId=" + workingStationId
				+ ", branch=" + branch
				+ ", counter=" + counter + ", timestamp=" + timestamp
				+ ", numberOperationPdl=" + numberOperationPdl + "]";
	}
	
}
